;;;
;;;
;;;	Author:
;;;		Henry C. Francis
;;;		425 N. Ashe St.
;;;		Southern Pines, NC 28387
;;;
;;;     http://paracadd.com
;;;	All rights reserved.
;;;
;;;Prior to DEFUN below (COMMAND ".undefine" "open") is required or this DEFUN will not
;;;redefine QSAVE (COMMAND ".undefine" "open") can be executed from here or anywhere
;;;else as long as it is called before this DEFUN
;;;
(DEFUN c:open (/)
  (SETQ princprfx (IF (AND debug_princs princprfx)
                    (STRCAT princprfx "  ")
                    (IF debug_princs
                      "[DEBUG]  "
                      ""
                    ) ;_ end of IF
                  ) ;_ end of IF
  ) ;_ end of SETQ
  (IF princdebugstrs NIL (LOAD "princdebugstrs" "\nFile PRINCDEBUGSTRS.LSP not loaded! "))
  (princdebugstrs (LIST "Begin execution of C:OPEN function.\n"))
  (IF save_file_chk NIL (LOAD "save_file_chk" "\nFile SAVE_FILE_CHK.LSP not loaded! "))
  (IF initandsdichk NIL (LOAD "initandsdichk" "\nFile INITANDSDICHK.LSP not loaded! "))
  (IF check_for_doslib NIL (LOAD "check_for_doslib" "\nFile CHECK_FOR_DOSLIB.LSP not loaded! "))
  (IF setprevdwg NIL (LOAD "setprevdwg" "\nFile SETPREVDWG.LSP not loaded! "))
  (IF myopen_fun NIL (LOAD "myopen_fun" "\nFile MYOPEN_FUN.LSP not loaded! "))
  (IF (EQ (GETVAR "dbmod") 0)
    (PROGN
      (SETQ mydbunmod T)
      (save_file_chk)
      (SETQ mydbunmod nil)
    ) ;_ end of PROGN
    (save_file_chk)
  ) ;_ end of IF
  (SETQ nodoslib T)
  (check_for_doslib)
  (SETQ re_mode (GETVAR "REGENMODE"))
  (initandsdichk)
;;;  (SETQ skip_save_chk T)
  (IF (EQ what_to_do 1)
    (PROGN
      (SETQ what_to_do nil)
      (IF debug_what_to_do NIL (LOAD "myopen_fun" "\nFile MYOPEN_FUN.LSP not loaded! "))
      (debug_what_to_do "Set what_to_do(4) to NIL")
    )
    (PROGN
;;;         (PRINC "\nrproj=")
;;;         (PRINC rproj)
      (IF c:proj
        (IF rproj
          (sel_proj rproj)
          (c:proj)
        ) ;_ end of if
        (IF (LOAD "proj")
          (IF rproj
            (sel_proj rproj)
            (c:proj)
          ) ;_ end of if
          (PROGN
            (SETQ skip_save_chk nil)
            (SETQ opnfil
		   (dos_getfiled "Select File"
		     (IF path_str path_str "")
		     "All Drawings|*.dwg|Design Plans|???plx*.dwg|Design Profiles|???prx*.dwg|Design Drawings|?st??x*.dwg;*base*.dwg;???plx*.dwg;???prx*.dwg;???scx*.dwg;???elx*.dwg|Sheets|0*.dwg;1*.dwg;2*.dwg;3*.dwg;4*.dwg;5*.dwg;6*.dwg;7*.dwg;8*.dwg;9*.dwg|Survey Base|cstecx*.dwg;cstsvx*.dwg;*base*.dwg|Points|*point*.dwg||"
		   )
;;;                   (GETFILED "Open Drawing" (GETVAR "dwgprefix") "DWG" 4)
            ) ;_ end of setq
            (IF (FINDFILE opnfil)
              (SETQ filact ".open")
              (SETQ filact ".new")
            ) ;_ end of if
            (PROGN
              (SETQ drvstr (SUBSTR opnfil 1 2))
              (SETQ dirstr
                     (STRCAT "\\" (SUBSTR opnfil 4 (- (STRLEN opnfil) 7)))
              ) ;_ end of setq
              (WHILE (/= (SUBSTR dirstr (STRLEN dirstr) 1) "\\")
                (SETQ dirstr (SUBSTR dirstr 1 (1- (STRLEN dirstr))))
              ) ;_ end of while
              (IF nodoslib
                nil
                (PROGN
                  (DOS_DRIVE drvstr)
                  (DOS_MKDIR dirstr)
                  (DOS_CHDIR "\\")
                  (DOS_CHDIR dirstr)
;;;                  (PRINC "\n  dirstr = ")
;;;                  (PRINC dirstr)
;;;                  (PRINC)
                ) ;_ end of progn
              ) ;_ end of if
              (SETQ opnstr (STRCAT "\"" opnfil "\""))
            ) ;_ end of progn
            (PROGN
              (SETQ skip_save_chk nil)
              (IF (AND (SETQ fvp_avail (SSGET "X" '((0 . "VIEWPORT"))))
                       (> (SSLENGTH fvp_avail) 1)
                  ) ;_ end of AND
                (SETVAR "regenmode" 1)
              ) ;_ end of IF
	      (setprevdwg)
              (IF (EQ filact ".new")
                (PROGN
                  (IF debug_princs
                    (PROGN
                      (PRINC (STRCAT "\n" princprfx " Execute (COMMAND filact opnstr). "))
                      (PRINC (STRCAT "\n" princprfx " filact=" filact))
                      (PRINC (STRCAT "\n" princprfx " opnstr=" opnstr))
                      (PRINC)
                    ) ;_ end of PROGN
                  )
                  (COMMAND filact opnstr)
                )
                (PROGN
                  (IF debug_princs
                    (PROGN
                      (PRINC (STRCAT "\n" princprfx " Execute (myopen_fun opnstr). "))
                      (PRINC (STRCAT "\n" princprfx " opnstr=" opnstr))
                      (PRINC)
                    ) ;_ end of PROGN
                  )
                  (myopen_fun opnstr)
                )
;;;		(MYOPENCMD opnstr)
              ) ;_ end of IF
;;;              (s::startup)
            ) ;_ end of progn
          ) ;_ end of progn
        ) ;_ end of if
      ) ;_ end of if
    ) ;_ end of PROGN
  ) ;_ end of IF
  (princdebugstrs (LIST "End execution of C:OPEN function.\n"))
  (SETQ princprfx
         (COND
           ((AND princprfx (WCMATCH princprfx "`[DEBUG`]   *"))
            (SUBSTR princprfx 1 (- (STRLEN princprfx) 2))
           )
           (debug_princs "[DEBUG]  ")
           (T "")
         ) ;_ end of COND
  ) ;_ end of SETQ
  (PRINC)
) ;_ end of defun
(DEFUN myownopencmd () (c:open)(PRINC))
